#include "moob.hpp"
#include <iostream>

cMoob::cMoob(int ID, float X, float Y, short TYPE, cMoobResources * RES, float ANGLE)
{
    id = ID;
    pos = new sPoint(X, Y);
    type = TYPE;
    angle = ANGLE;
    tmp = create_bitmap(TILE_SIZE, TILE_SIZE);
    res = RES;
}

cMoob::~cMoob()
{

}

void cMoob::draw(BITMAP * bufor, sPoint * show, sPoint * shift, bool ** fog, bool fogOn)
{
    if (pos->x < show->x || pos->x > show->x + bufor->w || pos->y < show->y || pos->y > show->y + bufor->h) return;
    if (fogOn) if (!fog[(int)pos->x/TILE_SIZE][(int)pos->y/TILE_SIZE]) return;

    int action = 0;

    blit(res->img, tmp, action * TILE_SIZE, (int)(frame) * TILE_SIZE, 0, 0, TILE_SIZE, TILE_SIZE);

    int X = pos->x - show->x;
    int Y = pos->y - show->y;

    if (action == 0) angle = -countAngle(mouse_x - shift->x - X, mouse_y - shift->y - Y);

    rotate_sprite(bufor, tmp, X - TILE_SIZE/2 + shift->x, Y - TILE_SIZE/2 + shift->y, ftofix(rtoa(angle) * 255 / 360));
}
